// =============================================================
// CCGI class
// ---------------------------------------
// Author : Woo-Hyun Kim
// Email : woorung@icu.ac.kr or woorung@nhncorp.com
// Date : Jun. 22, 2000
// =============================================================
#ifndef CCGIH
#define CCGIH
//------------------------------------------------------------------------
#include <fstream>
#include <iostream>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <assert.h>
//------------------------------------------------------------------------
using namespace std;
//------------------------------------------------------------------------
class CCGI;	
//------------------------------------------------------------------------
class entryNode {
	friend class CCGI;

private:
	char * entryName;
	char * entryData;
	char * entryFilename;
	long long int entryFilesize;

	entryNode * link;
};
//------------------------------------------------------------------------
class CCGI {
public:
	CCGI();
	CCGI(int);
	~CCGI();

	bool getFormData(void);
	int getEntryNum(void);

	char * getEntryName(const int);
	char * getEntryData(const int);
	char * getEntryFilename(const int);
	long long int getEntryFilesize(const int);

	char * getEntryDataByEntryName(const char *);
	char * getEntryFilenameByEntryName(const char *);
	long long int getEntryFilesizeByEntryName(const char *);

	bool writeToFileFromEntryData(const int,const char *);
	bool writeToFileFromEntryData(const char *,const char *);

	char * getContentType(void);
	char * getRequestMethod(void);
	int getContentLength(void);
	char * getQueryString(void);

	// to deal with hanguel file name
	char *toHanguelFileName(char *s);
	bool ACCEPTABLE(unsigned char a);
	char *MakePostString(char *s);

protected:
	bool __getMultiPartData(void);
	bool __getUrlEncodedData(void);
	bool __getEntryName(char * &,int);
	bool __getEntryData(char * &,int);
	void __plusToSpace(char *);
	void __escapeToChar(char * &);
	void __extractPath(char * &);

	entryNode * first;
	entryNode * current;

	int entryNum;

	int dataMaxSize;

private:
	bool __debugFlag;
	char *m_pszHanguelFileName;
};
//------------------------------------------------------------------------
#endif
